export function getFormatDateTime(e) {
	const date = new Date(e) || new Date();
	const year = date.getFullYear();
	const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1，并且保证是两位数  
	const day = String(date.getDate()).padStart(2, '0'); // 保证日期是两位数  
	const hours = String(date.getHours()).padStart(2, '0'); // 保证小时是两位数  
	var time = `${year}-${month}-${day}`;
	return time
}

// 当前时间的前一天
export function getFormatDatebeforeTime(e) {
	const date = new Date(e) || new Date();
	const year = date.getFullYear();
	const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1，并且保证是两位数  
	const day = String(date.getDate() - 1).padStart(2, '0'); // 保证日期是两位数  
	const hours = String(date.getHours()).padStart(2, '0'); // 保证小时是两位数  
	var time = `${year}-${month}-${day}`;
	return time
}

export function getTimeStamp(e) {
	var date = new Date(e);
	date.setDate(date.getDate());
	return date;
}
export function getFormatDate(date) {
	if (!date) date = new Date();
	var seperator1 = "-";
	var seperator2 = ":";
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	var hour = date.getHours();
	var minute = date.getMinutes();
	var second = date.getSeconds();
	if (month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if (strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	if (hour >= 0 && hour <= 9) {
		hour = "0" + hour;
	}
	if (minute >= 0 && minute <= 9) {
		minute = "0" + minute;
	}
	if (second >= 0 && second <= 9) {
		second = "0" + second;
	}
	var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
		" " + hour + seperator2 + minute +
		seperator2 + second;
	return currentdate;
}


export function getBefore7DateTime(inputDate) {
  const baseDate = inputDate ? new Date(inputDate) : new Date();
  const targetDate = new Date(baseDate);
  targetDate.setDate(targetDate.getDate() - 7); // 修正为7天前
  const year = targetDate.getFullYear();
  const month = String(targetDate.getMonth() + 1).padStart(2, '0');
  const day = String(targetDate.getDate()).padStart(2, '0');
  return `${year}-${month}-${day}`;
}